package com.ardo.utils;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

@Component
public class IPUtils {

    @Cacheable(value = "localIP", unless = "#result == null")
    public String localIP() {
        InetAddress ia = null;
        try {
            ia = ia.getLocalHost();
            System.out.println("打印IP：" + ia);
            return ia.getHostAddress().trim();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String s = new IPUtils().localIP();
        System.out.println(s);
    }
}
